#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time    : 2025/3/31 15:09
@Author  : HZP
@File    : config.py
"""
import os
from typing import Any

from .default_config import DEFAULT_CONFIG


def _get_env(key: str) -> Any:
    return os.environ.get(key, DEFAULT_CONFIG.get(key))


def _get_bool_env(key: str) -> bool:
    value: str = _get_env(key)
    return value.lower() == "true" if value is not None else False


class Config:
    """框架flask的配置内容"""

    LLM_MODEL_NAME: str = ""
    JWT_SECRET_KEY: str = ""

    def __init__(self):
        # 关闭wtf的csrf保护
        self.WTF_CSRF_ENABLED = _get_bool_env("WTF_CSRF_ENABLED")

        # 配置数据库配置
        self.SQLALCHEMY_DATABASE_URI = _get_env("SQLALCHEMY_DATABASE_URI")
        self.SQLALCHEMY_ENGINE_OPTIONS = {
            "pool_size": int(_get_env("SQLALCHEMY_POOL_SIZE")),
            "pool_recycle": int(_get_env("SQLALCHEMY_POOL_RECYCLE")),
        }
        self.SQLALCHEMY_ECHO = _get_bool_env("SQLALCHEMY_ECHO")

        # 配置大模型 model
        self.LLM_MODEL_NAME = _get_env("LLM_MODEL_NAME")
        # 配置jwt secret
        self.JWT_SECRET_KEY = _get_env("JWT_SECRET_KEY")
